﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace MSPToolkitSampleApp.ControlsXaml
{
    public partial class HTMLTextBoxSample : PhoneApplicationPage
    {
        public HTMLTextBoxSample()
        {
            InitializeComponent();
        }

        private void b_clicked(object sender, EventArgs e)
        {
            var ind = tb.SelectionStart;
            tb.SelectedText = string.Format("<b>{0}</b>", tb.SelectedText);
            tb.Focus();
            tb.SelectionStart = ind + 3;            
        }

        private void i_clicked(object sender, EventArgs e)
        {
            var ind = tb.SelectionStart;
            tb.SelectedText = string.Format("<i>{0}</i>", tb.SelectedText);
            tb.Focus();
            tb.SelectionStart = ind + 3;
        }

        private void u_clicked(object sender, EventArgs e)
        {
            var ind = tb.SelectionStart;
            tb.SelectedText = string.Format("<u>{0}</u>", tb.SelectedText);
            tb.Focus();
            tb.SelectionStart = ind + 3;
        }

        private void br_clicked(object sender, EventArgs e)
        {
            var ind = tb.SelectionStart;
            tb.SelectedText ="<br/>";
            tb.Focus();
            tb.SelectionStart = ind + 5;
        }

        private void HTMLTextBox_HyperlinkClick(object sender, MSPToolkit.Controls.HyperlinkClickEventArgs e)
        {
            MessageBox.Show(e.NavigationUri.ToString());
        }

        private void tb_GotFocus(object sender, RoutedEventArgs e)
        {
            TitlePanel.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void tb_LostFocus(object sender, RoutedEventArgs e)
        {
            TitlePanel.Visibility = System.Windows.Visibility.Visible;
        }
    }
}